#!/bin/sh

# This crappy script regenerates *.postinst & *.prerm from 
# some templates

# Generated by:
# $(grep Package: control|grep -v -E "(dev|-test|-doc)"|cut -d- -f2)
LIST="base sse sse2 sse3 core2sse3 amd64sse3 corei7sse3 altivec v9 ev6 2.0"

# The list of priority:
# http://wiki.debian.org/DebianScience/LinearAlgebraLibraries
LIST_PRIORITY=(30 35 40 45 50 55 60 60 60 60 60)

# Templates
POSTINST="libatlas3gf-template.postinst"
PRERM="libatlas3gf-template.prerm"
POSTINSTDEV="libatlas-template-dev.postinst"
PRERMDEV="libatlas-template-dev.prerm"
i=1
for pkg in $LIST; do

	target=$(echo $POSTINST|sed -e "s|template|$pkg|")
	targetprerm=$(echo $PRERM|sed -e "s|template|$pkg|")
	sed -e "s|PACKAGE|$pkg|g" -e "s|PRIORITY|${LIST_PRIORITY[${i}]}|g" $POSTINST > $target
	sed -e "s|PACKAGE|$pkg|g" $PRERM > $targetprerm

    targetdev=$(echo $POSTINSTDEV|sed -e "s|template|$pkg|")
    targetprermdev=$(echo $PRERMDEV|sed -e "s|template|$pkg|")
	
    sed -e "s|PACKAGE|$pkg|g" -e "s|PRIORITY|${LIST_PRIORITY[${i}]}|g" $POSTINSTDEV > $targetdev
    sed -e "s|PACKAGE|$pkg|g" $PRERMDEV > $targetprermdev
	i=$(($i + 1))
done
